home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / MM2_DEV / S / MOS / ARGCVIO.I < prev    next >
Encoding:
Modula Implementation  |  1990-11-10  |  3.8 KB  |  140 lines

  1. IMPLEMENTATION MODULE ArgCVIO;
  2.  
  3. (*$Y+,R-,C-*)
  4.  
  5. FROM SYSTEM IMPORT ASSEMBLER, ADDRESS, WORD, BYTE, TSIZE;
  6.  
  7. FROM PrgCtrl IMPORT ActiveProcess;
  8.  
  9. FROM InOut IMPORT RedirectOutput, RedirectInput;
  10.  
  11.  
  12. CONST MaxArgs = 63;
  13.  
  14. PROCEDURE InitArgCV ( VAR ArgC : CARDINAL; VAR ArgV : ARRAY OF PtrArgStr );
  15.  
  16.   VAR comlin : Address;
  17.       i, quote : Cardinal;
  18.       append, inword : Boolean;
  19.       p: Address;
  20.       new_stdin, new_stdout : PtrArgStr;
  21.  
  22.   (*$L-*)
  23.   PROCEDURE Peek (p:Address) : CHAR;
  24.     BEGIN
  25.       ASSEMBLER
  26.         MOVE.L  -(A3),A0
  27.         CLR.W   D0
  28.         MOVE.B  (A0),(A3)+
  29.         ADDQ.L  #1,A3
  30.       END
  31.     END Peek;
  32.   (*$L+*)
  33.   
  34.   (*$L-*)
  35.   PROCEDURE Poke (p:Address;v:Byte);
  36.     BEGIN
  37.       ASSEMBLER
  38.         SUBQ.L  #1,A3
  39.         MOVE.B  -(A3),D0
  40.         MOVE.L  -(A3),A0
  41.         MOVE.B  D0,(A0)
  42.       END
  43.     END Poke;
  44.   (*$L+*)
  45.   
  46.   PROCEDURE isspace (c:Char):Boolean;
  47.     BEGIN
  48.       RETURN (c=' ') OR (c=11c) OR (c=15c) OR (c=12c)
  49.     END isspace;
  50.   
  51.   PROCEDURE newWd;
  52.     BEGIN
  53.       IF argc <= HIGH (argv) THEN
  54.         ArgV[argc] := PtrArgStr(p);
  55.       END;
  56.       Inc (argc);
  57.     END newWd;
  58.   
  59.   PROCEDURE tstQuote (n:CARDINAL);
  60.     BEGIN
  61.       IF quote = n THEN
  62.         Poke (p,0C);
  63.         quote := 0
  64.       ELSIF ~inword & (quote=0) THEN
  65.         Poke (p,0C);
  66.         quote := n;
  67.         newWd
  68.       END
  69.     END tstQuote;
  70.   
  71.   BEGIN
  72.     new_stdin := Nil;
  73.     new_stdout := Nil;
  74.     inword := False;
  75.     quote := 0;
  76.     
  77.     comlin:= ActiveProcess();
  78.     Inc (comlin, 128);
  79.     
  80.     argc := 1;    (* always have at least program name *)
  81.     
  82.     p := comlin+1L;
  83.     
  84.     FOR i:= 1 TO ORD (Peek(comlin)) DO
  85.         IF isspace(Peek(p)) THEN
  86.             IF quote=0 THEN
  87.                 inword := False;
  88.                 Poke (p,0C)
  89.             ELSE
  90.                 Poke (p,' ')
  91.             END;
  92.         ELSIF Peek(p) = '"' THEN
  93.             tstQuote (1);
  94.         ELSIF Peek(p) = "'" THEN
  95.             tstQuote (2);
  96.         ELSE
  97.             IF ~inword & (quote=0) THEN
  98.                 inword := True;
  99.                 IF (Peek(p) = '<') THEN    (* redirect stdin *)
  100.                     new_stdin := p+1L
  101.                 ELSIF (Peek(p) = '>') THEN
  102.                     IF (Peek((p+1L)) = '>') THEN
  103.                         new_stdout := p+2L;    (* redirect and append stdout *)
  104.                         append := True
  105.                     ELSE
  106.                         new_stdout := p+1L; (* redirect stdout *)
  107.                         append := False
  108.                     END;
  109.                 ELSE
  110.                     (* not redirection, add to argv[] *)
  111.                     newWd
  112.                 END
  113.             END
  114.         END;
  115.         Inc (p);
  116.     END;
  117.     Poke (p,0C);  (* make sure last string is null terminated *)
  118.     
  119.     i:=argc;
  120.     WHILE i<=HIGH(argv) DO
  121.       ArgV[i] := PtrArgStr(p);
  122.       Inc (i)
  123.     END;
  124.     
  125.     (* Open redirection files now *)
  126.     IF new_stdin#Nil THEN
  127.         RedirectInput (new_stdin^)
  128.     END;
  129.     IF new_stdout#Nil THEN
  130.         RedirectOutput (new_stdout^,append)
  131.     END;
  132.     
  133.     argv[0] := p;          (* no program name *)
  134.     
  135.   END InitArgCV;
  136.  
  137. END ArgCVIO.
  138. ə
  139. (* $FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$00000209$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566E$FFFD566EÇ$00000464T.......T.......T.......T.......T.......T.......T.......T.......T.......T.......$00000209$00000051$FFEDB15C$FFECCFDB$FFECCFDB$000000C8$00000464$00000481$00000468$FFEDB15C$FFEDB15C$00000027$00000084$FFEDD2CF$000005F7$00000606ãÇÇ*)
  140.